Heap storage is a set of memory locations that are used by objects that are dynamically allocated during the execution of a program. A heap is managed by maintaining a list of the free memory locations within the heap. As the program executes, heap storage is allocated from the pool of free memory space and released either explicitly by the program or implicitly when the memory locations are no longer used. When the heap storage is released explicitly, the memory locations are added to a pool of free memory space.
Garbage is often used to describe the allocated heap storage that is no longer accessed by the program. Garbage collection is the process of reclaiming the memory locations that are no longer accessed by the program. A garbage collector typically marks the memory locations that are still being used and then reclaims the unmarked portions which are added to the pool of free memory space. Garbage collection adds a considerable overhead to a program since the garbage collector has to keep track of the objects that are referenced and then has to release the unreferenced objects on the fly. Techniques that minimize the computational overhead of a garbage collector are essential to sustaining the performance of a program.